package com.team.ai.controller;

import com.team.ai.entity.ResultEntity;
import com.team.ai.service.BookService;
import com.team.ai.service.CarouselService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Carousel/")
public class CarouselController {
    private static final Logger logger = LoggerFactory.getLogger(CarouselController.class);//日志getLogger需要传入的类名

    @Resource
    CarouselService carouselService;

    /**
     * 增
     * @return
     */
    @PostMapping("insert")
    private String insert(
            @RequestParam(value = "img",defaultValue = "-1") String img,
            @RequestParam(value = "bookid",defaultValue = "-1") int bookid

    ){
        if (img.equals("")||bookid==-1){
            return ResultEntity.fail(-10002);
        }
        return carouselService.insert(img, bookid);

    }

    /**
     * 删
     * @param id
     * @return
     */
    @DeleteMapping("delete")
    private String delete(
            @RequestParam(value = "id",defaultValue = "-1") int id

            ){
        if (id==-1){
            return ResultEntity.fail(-10002);
        }
        return carouselService.delete(id);
    }

    /**
     * 改
     * @return
     */
    @PostMapping("update")
    private String update(

            @RequestParam(value = "img",defaultValue = "-1") String img,
            @RequestParam(value = "bookid",defaultValue = "-1") int bookid,
            @RequestParam(value = "id",defaultValue = "-1") int id
    ){
        if (bookid==-1||img.equals("")||id==-1){
            return ResultEntity.fail(-10002);
        }
        return carouselService.update(img, bookid, id);

    }

    /**
     * 查
     * @return
     */
    @GetMapping("selectList")
    private String selectList(

    ){
        return carouselService.selectList();
    }
    @GetMapping("selectDetail")
    private String selectDetail(
            @RequestParam(value = "id",defaultValue = "-1") int id

    ){
        return carouselService.selectDetail(id);

    }

}
